<?php
namespace app\common\model\customer;
use think\Model;
use app\api\controller\Pub;

class Street extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'street';
    protected $pk    = 'StreetId';

    /**
     * 获取街道数组
     * @return [type] [description]
     */
    public static function getarray(){
        $data = Street::getlist();
        $list = [];
        foreach ($data as $key => $value) {
            $value['name'] = $value['Street'];
            if(empty($list) || empty($list[$value['District']])){
                $list[$value['District']] = ['name'=>$value['District'],'list'=>[$value]];
            }else{
                $list[$value['District']]['list'][] = $value;
            }
        }
        $res = [];
        $index = 0;
        foreach ($list as $key => $value) {
            $res[$index++] = $value; 
        }
        return $res;
    }
    /**
     * 获取街道列表
     * @return [type] [description]
     */
    public static function getlist(){
        $data = Street::select()->toArray();
        return $data;
    }

    /**
     * 获取街道详情
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public static function getinfo($id){
        $data = Street::get($id);
        return $data;
    }

}
